package cn.quan.dlairport;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class FlightAdapter extends ArrayAdapter<FlightItem> {
	private List <FlightItem> mItems;
	private int mTextViewResourceId;
	private Context mContext;
	private LayoutInflater mInflater;
	
	public FlightAdapter(Context context, int textViewResourceId,List<FlightItem> items) {
		super(context, textViewResourceId,items);
		// TODO Auto-generated constructor stub
		this.mItems = items;
		this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.mContext = context;
		this.mTextViewResourceId = textViewResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = convertView;
		if (v == null){
			v = mInflater.inflate(mTextViewResourceId, null);
		}
		final FlightItem item=(FlightItem)mItems.get(position);
		TextView text1 = (TextView)v.findViewById(R.id.text1);
		TextView text2 = (TextView)v.findViewById(R.id.text2);
		TextView text3 = (TextView)v.findViewById(R.id.text3);
		TextView text4 = (TextView)v.findViewById(R.id.text4);
		TextView text5 = (TextView)v.findViewById(R.id.text5);
		TextView text6 = (TextView)v.findViewById(R.id.text6);
		TextView text7 = (TextView)v.findViewById(R.id.text7);
		text1.setText(item.flightNo);
		text2.setText(item.flightFrom+"->"+item.flightTo);
		text3.setText(item.flightStart);
		text4.setText(item.flightStartReal);
		text5.setText(item.flightEnd);
		text6.setText(item.flightEndReal);
		text7.setText(item.flightStatus);
		//是否变化
		if(item.flightStartRealRefresh){
			text4.setBackgroundColor(Color.YELLOW);//有变化
		}else{
			text4.setBackgroundColor(Color.BLACK);
		}
		if(item.flightEndRealRefresh){
			text6.setBackgroundColor(Color.YELLOW);
		}else{
			text6.setBackgroundColor(Color.BLACK);
		}
		
		return v;
	}

    private final String TAG = "**FLIGHT";

}
